﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace yule.CodeBuilder.Controllers
{
    public class UserController : BaseController
    {
        /// <summary>
        /// 用户列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {

            yule.IDAL.Cms.IType type = this.ServiceContext.CreateService<yule.IDAL.Cms.IType>();
            yule.IDAL.Sys.IUser u = this.ServiceContext.CreateService<yule.IDAL.Sys.IUser>();


            yule.IService.Sys.IUser userSvc = this.ServiceContext.CreateService<yule.IService.Sys.IUser>();

            IList<yule.Model.Sys.User> list = userSvc.GetList();

            return View(list);
        }

        /// <summary>
        /// 明细
        /// </summary>
        public ActionResult Details(string id)
        {

            yule.IService.Sys.IUser userSvc = this.ServiceContext.CreateService<yule.IService.Sys.IUser>();

            ViewData.Model = userSvc.GetUser(id);

            if (this.Request.IsAjaxRequest())
            {
                return this.PartialView();
            }
            else
            {
                return this.View();
            }
        }


        /// <summary>
        /// 删除页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Delete(string id)
        {
            yule.IService.Sys.IUser userSvc = this.ServiceContext.CreateService<yule.IService.Sys.IUser>();

            userSvc.Delete(id);

            return this.RedirectToAction("Index");
        }

        /// <summary>
        /// 插入页面
        /// </summary>
        /// <returns></returns>
        [OutputCache(Duration = 60 * 60)]
        public ActionResult Insert()
        {
            if (this.Request.IsAjaxRequest() == true)
            {
                return this.PartialView();
            }
            else
            {
                return this.View();
            }
        }

        /// <summary>
        /// 执行插入
        /// </summary>
        /// <returns></returns>
        public ActionResult DoInsert(yule.Model.Sys.User insertModel)
        {

            yule.IService.Sys.IUser userSvc = this.ServiceContext.CreateService<yule.IService.Sys.IUser>();

            insertModel.Id = yule.Util.Id.NewId();

            int val = userSvc.Insert(insertModel);

            return this.RedirectToAction("Index");
        }


    }
}
